<?php 
	$this->set("hideLayoutTitle",true);
	$itemScope = "";
	if(cr("ListingConfig.enable_rich_snippets"))
	{
        $entity = "Thing";
        $schemaUrl = "http://schema.org/";
        if(cr("ListingConfig.snippet_entity"))
        {
          $entity = cr("ListingConfig.snippet_entity");
        }
        $schemaUrl = "http://schema.org/".$entity;
		$itemScope = 'itemscope itemtype="'.$schemaUrl.'"';
	}
	$openGraph = array("og:title"=>$listingData['Listing']['title'],'og:site_name '=>cr("cmsConfig.Backend.siteName"),
				"og:url"=>cr("cmsConfig.Backend.siteUrl").$listingData['Listing']['viewUrl'],
				"og:description" => $listingData['Listing']['description'],
				"og:image" => cr('cmsConfig.Backend.siteUrl').$listingData['Listing']['image'],
				"fb:app_id" => cr("FacebookConfig.appId")
			);
	$openGraphContent = "";
	foreach($openGraph as $metaProperty => $metaContent)
	{
		$metaContent = htmlentities($metaContent);
		$openGraphContent .= "<meta property='$metaProperty' content='$metaContent' />";
	}
	$this->addScript($openGraphContent);
?>
<meta itemprop="name" content="<?php echo h($listingData['Listing']['title'])?>" />
<meta itemprop="url" content="<?php echo Router::url($listingData['Listing']['viewUrl'],true);?>" />
<meta itemprop="image" content="<?php echo Router::url($listingData['Listing']['image'],true)?>" />
<section class="hauptseite lists_detail"> 
	<div class="container"> 
		<div class="row"> 
			 <div class="row_detail">
				<div class="col-md-8 col_left">  
					<div class="bg_black">
						<div class="each_line">
							<div id="slider_big" class="flexslider">
							  	<ul class="slides">
							  		<?php 
									foreach($listingAssets as $listingAsset)
									{
										$listingAsset = $listingAsset['ListingAsset'];
										?>
										<li>
											<?php echo $html->image($listingAsset['file_url'],array('thumb'=>array('crop'=>true,'width'=>715,'height'=>450)));?>
										</li>				
									<?php
									}
									?>
							  </ul>
							</div><!--slider_big-->
							<div class="link_view_up">
								<?php
									$allowImageLinks = true;
									if(AppUtility::allowPaidListing())
									{
										$EffectivePlan = cri("PaidListings.ListingPlan")->getEffectivePlan($listingData['Listing']['id']);
										if($EffectivePlan->limitImages())
										{
											$allowImageLinks = false;
											$allowedImagesCount = $EffectivePlan->getAllowedTotalImagesCount();
							 
											if($allowedImagesCount > 0 && count($listingAssets) < ($allowedImagesCount - 1))
											{
											  
												if($listingData['Listing']['owner_id'] == $session->read("Auth.User.id") || $EffectivePlan->allowGallery())
												{
													$allowImageLinks = true;
												}
											}
										}
									}
								?>
								<?php if($allowImageLinks){?>
									<?php echo $html->link(__('Upload pic'),array('controller'=>'listing_assets','action'=>'add',$listingData['Listing']['id']),array('class'=>'link_upload'));?>
								<?php } ?>
								<span class="line_h">|</span> 
								<?php if(count($listingAssets) || !AppUtility::allowPaidListing()){?>   
									  <?php echo $html->link(__('View All Pics'),array("controller"=>"listing_assets",'action'=>'index','listing','listingId'=>$listingData['Listing']['id']),array('class'=>'link_viewall togallerylink'))?>
								  <?php } ?>
							</div><!--link_view_up-->
						</div><!--each_line-->
							
						<div class="each_line padd">
							 <h2 class="h2_title_detail"><?php echo $this->pageTitle?></h2>
							 <?php 
								$userReviewCount = '<div style="float:left;margin-left:85px">('.'<span>'.$listingData['Listing']['review_count'].'</span>  '.__('reviews').')</div>';
								$userRating = $listingData['Listing']['userAvg'];
								$editorRating = $listingData['Listing']['editorialAvg'];
								$userRatingHtml = $rating->display(array('rating'=>$userRating,'before_text'=>$userReviewCount,'tooltip'=>__('User Rating').' '.number_format($userRating,1)));
								$editorRatingHtml = $rating->display(array('rating'=>$editorRating,'class'=>'editor_rating_star_value','tooltip'=>__('Editor Rating').' '.number_format($editorRating,1)));
					
								$img = $html->image($listingData['Listing']['image'],array('thumb'=>array('crop'=>true,'width'=>200,'height'=>150),'class'=>'thumbnail','alt'=>sprintf(__("%s picture"),$listingData['Listing']['title'])));
							?>	
							 <div class="ratings">
								<?php echo $userRatingHtml;?>
								<?php //show editorial rating if "disableEditorReviews" config is enabled.
								if(cr('GeneralConfig.disable_editor_reviews') != 1)
								{
									echo $editorRatingHtml;
								}?>
								<?php 
								  $totalReviewCount = $listingData['Listing']['review_count'];
								  $totalRating = ($listingData['Listing']['userAvg']);
								  if($listingData['Listing']['editorialAvg'])
								  {
									$totalReviewCount++;
									$totalRating = ($totalRating + $listingData['Listing']['editorialAvg'])/2;
								  }
								  if($totalReviewCount && cr("ListingConfig.enable_rich_snippets") && $entity != "Thing"){
								?>
								  <span itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
									<meta itemprop="reviewCount" content="<?php echo $totalReviewCount?>"/>
									<meta itemprop="ratingValue" content="<?php echo $totalRating?>"/>
									<meta itemprop="bestRating" content="<?php echo Review::RATING_MAX_VALUE?>>"/>
								  </span>
								 <?php } ?>
							</div> <!--ratings-->
							<?php 
								if(cr("FacebookConfig.appId") && cr("ListingConfig.enable_fb_like"))
								{
									$fbLikeUrl = $html->url($listingData['Listing']['viewUrl'], true);
									//$fbLikeUrl = rawurlencode($fbLikeUrl);
									?>
									<div class="iframe_facebook">
										<iframe frameborder=0  width="200" height="22" src="http://www.facebook.com/plugins/like.php?href=<?php echo $fbLikeUrl ?>&width=100&layout=button_count&action=like&show_faces=true&share=false&height=21&appId=<?php echo cr("FacebookConfig.appId") ?>"></iframe>
									</div>
									<?php 
								}
								?>
							<div class="clear"></div>
							<div class="listing_content">
								<div class="W_category_name">
									<span class="category_name"><?php echo $listingInformation->showListingCategories($listingData);?></span> <br>
									<div class="address">
										<?php echo $listingData['Listing']['location_search_cache'];?><br>
										<?php echo $listingData['Listing']['phone'];?><br>
										<a href="<?php echo 'http://'.$listingData['Listing']['website'];?>" class="outlink" target="__blank"><?php echo $listingData['Listing']['website'];?></a><span> - </span>
										<?php 
											if($listingData["Listing"]['lat'] && $listingData["Listing"]['lng'])
											{
												echo $html->link(__("Get directions"),array("plugin"=>null,"controller"=>"listings","action"=>"getDirections",$listingData["Listing"]["slug"]),array("escape"=>false,"class"=>"button get_directions"));
											}
										?>
									</div> 
								</div><!--W_category_name-->
			
								<?php
									//render element to show custom field info 
									echo $this->element('listing_view_fields',array('ListingModelObj'=>$ListingModelObj,'listingDefaultFields'=>$listingDefaultFields));
								?>			
								<div class="description">
									<?php
									if(!empty($listingData['Listing']['description']))
									{?>
									<hr> <b><?php echo __('Description')?>:</b>
									<?php 
										if(cr('ListingConfig.flay_text'))
										{
											echo $appHtml->flayText($listingData['Listing']['description'],cr('ListingConfig.flay_text'));
										}else
										{
											echo $listingData['Listing']['description'];
										}
									}
									?>   
								</div><!--description-->
								<?php  if(cr("GeneralConfig.enable_tags")){?>
								<b><?php echo __('Tags')?>:</b>
								<?php
								if($listingData['Listing']['tags'])
								{
									$tagsToShow = '';
									foreach($listingData['Listing']['tags'] as $tag)
									{
										$tagsToShow .=  $html->link($tag['tag'],'/listings/index/tags/'.$tag['slug']).',';
									}
									echo '<span itemprop="keywords">'.substr($tagsToShow,0,-1).'</span>';
								}else
								{
									echo __('N/A');
								}
								?>
								<?php }?>
								<div class="clear"></div>
								<div class="review_bottom">
									<?php if($session->read('Auth.User')){?>
										<div class="button">
											<i class="fa fa-heart"> </i> <?php echo $userContent->toggleFavorites($listingData['Listing']['id'],'Listing');?> 
										</div>
									<?php }?>     
									<div class="button"><i class="fa fa-envelope"> </i> <?php echo $html->link(__('Send to friends'),'/inviteFriends/'.$listingData['Listing']['id'],array('class'=>''))?></div>
									<?php 
									$isOwner = cr("ListingConfig.business_owner") && $session->read("Auth.User.id") && $listingData['Listing']['owner_id'] == $session->read("Auth.User.id");
									if($hasReviewd == false && $isOwner == false){
										echo " <div class='button'><i class='fa fa-star'> </i> ".$html->link(__('Write a Review'),'/reviews/add/'.$listingData['Listing']['id'],array());
										echo " </div> ";
									}
									?>     
								</div>
								<div class="wrap_st_sharethis_large">
									<?php echo $appHtml->shareLinks();?>      
								</div><!--wrap_st_sharethis_large-->
			
								<?php
								if(cr("DealConfig.enable_deals"))
								{
									if(isset($deals) && !empty($deals))
									{
										echo $this->element('listing_deals_element',array('deals'=>$deals,'plugin'=>'deals','showDeleteButton'=>(($isOwner == true)?true:false)));
									}
								}
								?>
			
								<div class="reviews_section" id="listing_reviews_<?php echo $listingData['Listing']['id']?>">
									<?php
									//showing editorial review.
									if(cr('GeneralConfig.disable_editor_reviews')!= 1)
									{?>	
										<?php 
										if(!empty($editorialReview))
										{?>
											<h3><?php echo __('Editor Review')?></h3>
											<?php echo $this->element('reviews', array('showAvatar'=>true,'reviews' => array($editorialReview),'view_type'=>'blog_view', 'full_description' => true));?>
										<?php }?>
									<?php 
									}?>
									<h3><?php echo __("User Reviews");?> (<?php echo $listingData['Listing']['review_count']?>)</h3>
									<?php echo $ajax->div('/reviews/index/listing/listingId:'.$listingData['Listing']['id'].'/full_description:true', array('preload' => true, 'recursive' => false));?><!--w_review_block-->
								</div><!--reviews_section--> 
			
							</div><!--listing_content--> 
						</div><!--padd -->  
			
					</div><!--bg_black--> 
				</div><!--col_left-->
			
				<div class="col-md-4 col_right">
				  <?php echo $this->element('listing_view_map');?>
				  
<!-- side_blog_view --> 
				</div><!--col_right--> 
			</div><!--/.row_detail -->

		</div><!--/.row-->
	</div> <!--/.container-->
</section> <!-- /.hauptseite-->